package com.syy.spider.service.impl;

import com.syy.spider.dao.LoginMapper;
import com.syy.spider.pojo.Admin;
import com.syy.spider.pojo.User;
import com.syy.spider.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginServiceImpl implements LoginService {
    @Autowired
    private LoginMapper loginMapper;
    @Override
    public boolean login(User user) {
        User selectResult = loginMapper.selectUserByUserName(user.getUsername());
        if (selectResult!=null){
            if (selectResult.getPassword().equals(user.getPassword())){
                return true;
            }else {
                return false;
            }
        }else {
            return false;
        }
    }

    @Override
    public boolean regist(User user) {
        User userSelect = loginMapper.selectUserByUserName(user.getUsername());
        if (userSelect==null){
            int result = loginMapper.addUser(user.getUsername(),user.getPassword());
            return true;
        }else {
            return false;
        }
    }

    @Override
    public boolean adminLogin(Admin admin) {
        Admin selectResult = loginMapper.selectAdminByUserName(admin.getUsername());
        if (selectResult!=null){
            if (selectResult.getPassword().equals(admin.getPassword())){
                return true;
            }else {
                return false;
            }
        }else {
            return false;
        }
    }
}
